Skip to content

Comments

add opencode installer script#116

Closed
onelesd wants to merge 1 commit intoobra:mainfrom
onelesd:dseleno/feat/install-opencode-sh
Closed

add opencode installer script#116
onelesd wants to merge 1 commit intoobra:mainfrom
onelesd:dseleno/feat/install-opencode-sh

Conversation

@onelesd
Copy link
Contributor

@onelesd onelesd commented Nov 19, 2025

This installer script copies the skills, agents and commands into opencode's expected dir structure.

When used with https://github.com/malhashemi/opencode-skills the result is a superpowers-capable opencode.

It is meant to be run once, and then whenever the superpowers repo is updated with a git pull. The installer will copy new skills if they are found and prompt to overwrite or ignore skills which have changed.

Motivation and Context

I wanted to use superpowers in opencode.

How Has This Been Tested?

Tested with both a fresh opencode install and an existing install.

Breaking Changes

They will need to use the opencode-skills plugin which is mentioned by the installer.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Summary by CodeRabbit

  • New Features
    • Added interactive installer script for OpenCode configuration management
    • Features automatic file change detection and comparison
    • Prompts users for conflict resolution when files are modified
    • Displays comprehensive summary of planned actions before execution
    • Supports flexible target directory selection with optional directory creation
    • Includes file-by-file outcome reporting during installation

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Walkthrough

A new bash installer script is introduced that syncs content from three source directories (agents, commands, skills) into an OpenCode config directory using a four-phase flow: planning, conflict resolution, summary presentation, and file execution with checksum-based change detection.

Changes

Cohort / File(s) Summary
New OpenCode Installer Script
install-opencode.sh
Introduces interactive multi-phase installer for syncing agents, commands, and skills directories. Implements checksum-based change detection, conflict resolution via user prompts, summary reporting, and file copy operations with error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script as install-opencode.sh
    participant FS as File System

    User->>Script: Execute script
    Note over Script: Phase 1: Scan & Plan
    Script->>FS: Read source directories
    Script->>FS: Calculate SHA-256 checksums
    Script->>Script: Build action plan (new/skip/prompt)

    Note over Script: Phase 2: Resolve Conflicts
    loop For changed files
        Script->>User: Prompt: overwrite or skip?
        User-->>Script: User decision
        Script->>Script: Record final action
    end

    Note over Script: Phase 3: Present Summary
    Script->>User: Display planned changes<br/>(new, overwrite, skip)
    Script->>User: Note about opencode.json

    Note over Script: Phase 4: Execute
    Script->>FS: Create target directories
    loop For each file
        alt File action
            Script->>FS: Copy file
            Script->>User: Report (copied/overwritten/skipped)
        else Error
            Script->>User: Report error
        end
    end
    Script->>User: Installation complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Multi-phase control flow with distinct logic in each phase requires careful verification of interaction between phases
  • Checksum-based change detection logic and comparison mechanisms should be validated
  • User prompting and conflict resolution flow needs review for edge cases and response handling
  • File operations (copy, directory creation) and error handling warrant attention to ensure robustness

Poem

🐰 A script hops forth with purpose bright,
Syncing skills and commands to the right,
Four phases dance in perfect time,
Checksums verify, no file left to mime,
OpenCode awaits its treasure clean! 🎯✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add opencode installer script' is directly related to the changeset, which introduces a new bash installer script (install-opencode.sh) for the OpenCode system.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
install-opencode.sh (1)

107-108: Separate variable declaration from assignment (SC2155 best practice).

Shellcheck recommends declaring and assigning variables separately to avoid masking return values. While this specific case is low-risk, adopting the pattern improves consistency:

- local source_checksum=$(calculate_checksum "$source_file")
- local target_checksum=$(calculate_checksum "$target_file")
+ local source_checksum
+ source_checksum=$(calculate_checksum "$source_file")
+ local target_checksum
+ target_checksum=$(calculate_checksum "$target_file")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02c8767 and 3602b32.

📒 Files selected for processing (1)
  • install-opencode.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.11.0)
install-opencode.sh

[warning] 79-79: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 107-107: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 108-108: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 138-138: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 138-138: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 203-203: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 203-203: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 203-203: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)


[warning] 203-203: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)

🔇 Additional comments (7)
install-opencode.sh (7)

96-119: Excellent file handling with null-byte delimiters.

The use of find ... -print0 with IFS= read -r -d '' correctly handles filenames with spaces, newlines, and special characters. This is a best practice implementation.


44-67: Well-structured user interaction with proper directory handling.

The prompts correctly use -n 1 -r flags for single-character input, handle tilde expansion, and include confirmation before creating directories. The directory creation logic properly checks existence, prompts for confirmation, and handles creation errors.


285-317: Solid Phase 4 execution logic with comprehensive error handling.

The file copy operations properly:

  • Skip marked files (line 287-289)
  • Create required directories with error recovery (lines 292-299)
  • Copy files with inline error handling (line 305)
  • Track successes and errors separately (lines 306-316)

The implementation correctly continues processing remaining files after errors, which is appropriate for an installer script.


73-129: Phase 1 scanning implementation is correct and handles missing directories gracefully.

The scanning logic properly detects changes via SHA-256 checksum comparison and categorizes actions appropriately. Skipping non-existent source directories with warnings is reasonable behavior for an installer.


131-186: Phase 2 conflict resolution handles user input robustly with proper loop validation.

The implementation correctly:

  • Prompts only for changed files (line 141)
  • Validates user input in a loop (lines 151-170)
  • Updates decisions to a new temp file (line 175)
  • Replaces the original with the updated decisions (line 179)
  • Tracks and reports conflict count (lines 142, 181-185)

188-264: Phase 3 summary display is informative with appropriate user guidance.

The phase correctly:

  • Categorizes and sorts all planned changes (lines 205-223)
  • Displays each category with clear formatting (lines 226-250)
  • Checks for OpenCode configuration files (lines 252-264)
  • Provides helpful next-steps guidance

338-348: Next steps section provides clear post-installation guidance.

The final instructions correctly guide users to enable the opencode-skills plugin and restart OpenCode. The optional AGENTS.md creation step is helpful.


# Create temp file to store file metadata
TEMP_FILE=$(mktemp)
trap "rm -f $TEMP_FILE" EXIT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix cumulative trap statements and use single quotes to delay variable expansion.

The trap statement at line 79 is replaced (not cumulative) at line 138, causing $TEMP_FILE cleanup to be lost. Additionally, Shellcheck warns (SC2064) that variables should be quoted to prevent expansion at definition time rather than exit time.

Each trap statement should use single quotes and include all cleanup files:

- trap "rm -f $TEMP_FILE" EXIT
+ trap 'rm -f "$TEMP_FILE"' EXIT

Then at line 138, replace (not supplement) with all files:

- trap "rm -f $TEMP_FILE $TEMP_ACTIONS" EXIT
+ trap 'rm -f "$TEMP_FILE" "$TEMP_ACTIONS"' EXIT

And at line 203:

- trap "rm -f $TEMP_FILE $TEMP_NEW $TEMP_OVERWRITE $TEMP_SKIP" EXIT
+ trap 'rm -f "$TEMP_FILE" "$TEMP_NEW" "$TEMP_OVERWRITE" "$TEMP_SKIP"' EXIT

Also applies to: 138-138, 203-203

🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 79-79: Use single quotes, otherwise this expands now rather than when signalled.

(SC2064)

Comment on lines +195 to +197
NEW_COUNT=0
OVERWRITE_COUNT=0
SKIP_COUNT=0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Initialize SKIP_COUNT variable with other count variables.

SKIP_COUNT is only assigned during the Phase 3 loop, while NEW_COUNT and OVERWRITE_COUNT are properly initialized beforehand. With set -u enabled (line 2), uninitialized variables cause errors. For consistency and safety, initialize SKIP_COUNT with the others:

  # Count actions
  NEW_COUNT=0
  OVERWRITE_COUNT=0
+ SKIP_COUNT=0

And remove the implicit initialization at line 219:

- SKIP_COUNT=$((SKIP_COUNT + 1))
+ SKIP_COUNT=$((SKIP_COUNT + 1))  # Now explicitly initialized above

Also applies to: 219-219

🤖 Prompt for AI Agents
In install-opencode.sh around lines 195 to 197, SKIP_COUNT is not initialized
alongside NEW_COUNT and OVERWRITE_COUNT which causes failures under set -u; add
SKIP_COUNT=0 to that block to initialize it, and remove the later implicit
initialization at line 219 so the variable is only set once at the top.

@jihchi
Copy link

jihchi commented Nov 19, 2025

Thank you! Great to see opencode support being added.

It would help to update README.md with instructions for getting started with the script.

@aaryan-rampal
Copy link

Haha i did the same thing. I'll test yours and see if there's anything I did different which you might be able to

@aaryan-rampal
Copy link

aaryan-rampal commented Nov 20, 2025

So I tried this, and it seems to break because Opencode is stricter with YAML formatting for the agents. This is how Claude put it after I fixed it:

The YAML frontmatter in code-reviewer.md has an unquoted description field containing XML-like tags (, ). YAML requires these special characters to be quoted. Fix by wrapping the
entire description value in double quotes: description: "Use this agent when... ..."

Maybe your script should auto parse any agents which exist

Edit: Tested using Opencode 1.0.80

Edit 2: Moreover, the code reviewer sonnet model name is not valid. This probably needs to be either hardcoded or not set (to inherent the parent model the user is using on opencode)

Edit 3: I see you already noticed this in #115. But the model problem still remains

@onelesd
Copy link
Contributor Author

onelesd commented Nov 20, 2025

Edit 2: Moreover, the code reviewer sonnet model name is not valid. This probably needs to be either hardcoded or not set (to inherent the parent model the user is using on opencode)

the hacky thing to do would be to strip the model setting, or map them to opencode model names.

however, for this "dumb" installer it would be better if this was abstracted upstream before the installers for claude/codex/opencode see it. this is a bigger change that we'd need @obra to weigh in on.

@obra
Copy link
Owner

obra commented Nov 21, 2025

Thanks so much for this PR. Have any of the folks here looked at what it'd take to do it as a 'proper' opencode plugin using their install and extension mechanisms? I worry a little bit about a copy-to-install kind of workflow.

The skill suite does need to be slightly better abstracted to support non-claude-code models and harnesses. For Codex, specifically with the GPT5 series models, we can get away with a custom bootstrap with a mapping table, but the right thing is probably to make all the skills cleaner and have a mapping table for each platform.

I think the code-reviewer subagent should probably be retired in favor of 'generic subagent with prompting'

The other opencode PR that reuses most of the codex bootstrap looked generally pretty good to me, but also I've only been playing with opencode for the past couple of days.

@obra
Copy link
Owner

obra commented Nov 24, 2025

I just landed a full opencode implementation (as a plugin, with tools). Install instructions are in the README. I'd love to know how it works for folks. (I'm closing out this PR for now)

@obra obra closed this Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants